/*
 * Copyright 2006 Berry Crawford
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.judo.generate.java;

import java.util.ArrayList;

import org.judo.generate.CodeGenerator;
import org.judo.generate.GenerationException;

public class Field implements CodeGenerator
{
	private String visibility;
	private boolean staticVar;
	private String type;
	private String varName;
	private String assignmentText;
	private int tabs;
	
	protected ArrayList<String> annotations = new ArrayList<String>();

	public void addAnnototation(String annotationCode)
	{
		annotations.add(annotationCode);
	}
	
	public String generate() throws GenerationException
	{
		String code = "";
	
		for (String annotation:annotations)
			code += ClassGenerator.tabs(tabs)+annotation+"\n";
		
		code += ClassGenerator.tabs(tabs)+visibility+" ";
		
		if (staticVar)
			code += "static ";
		
		code += type+" "+varName+" ";
		
		if (assignmentText != null)
			code += "= "+assignmentText;
		
		code += ";\n";
		
		return code;
	}
	
	public void setTabs(int count)
	{
		tabs = count;
	}
	
	public String getAssignmentText()
	{
		return assignmentText;
	}

	public void setAssignmentText(String assignmentText)
	{
		this.assignmentText = assignmentText;
	}

	public String getType()
	{
		return type;
	}

	public void setType(String type)
	{
		this.type = type;
	}

	public String getVarName()
	{
		return varName;
	}

	public void setVarName(String varName)
	{
		this.varName = varName;
	}

	public String getVisibility()
	{
		return visibility;
	}

	public void setVisibility(String visibility)
	{
		this.visibility = visibility;
	}

	public Field(boolean staticVar,String visibility, String type, String varName, String assignmentText, int tabs)
	{
		super();
		
		this.visibility = visibility;
		this.type = type;
		this.varName = varName;
		this.assignmentText = assignmentText;
		this.tabs = tabs;
		this.staticVar = staticVar;
	}

	public boolean isStaticVar()
	{
		return staticVar;
	}

	public void setStaticVar(boolean staticVar)
	{
		this.staticVar = staticVar;
	}
}
